package com.testwaterfall;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

    private RecyclerView mRecyclerView;
    private RecyclerView.LayoutManager mLayoutManager;
    private WaterFallAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        //设置布局管理器为2列，纵向
        mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        mAdapter = new WaterFallAdapter(this, buildData());
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(mAdapter);
    }

    //生成6个明星数据，这些Url地址都来源于网络
    private List<PersonCard> buildData() {
        String[] names = {"邓紫棋","范冰冰","杨幂","Angelababy","唐嫣","柳岩"};
        String[] imgUrs = {"http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740344015.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/15174034406.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740344101.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740344147.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740575311.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740723118.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740723282.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740723603.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740723763.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740724071.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740724275.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740724717.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740724902.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740725458.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/15174072564.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740725775.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/15174072586.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/15174076316.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740763304.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740763778.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740763887.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740764155.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740764265.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/15174076448.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/15174076465.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740764798.jpg",
                "http://bmvnxw.img48.wal8.com/img48/17286616_20180131130226/151740765044.jpg"
        };

        List<PersonCard> list = new ArrayList<>();
        for(int i=0;i<33;i++) {
            PersonCard p = new PersonCard();
            p.avatarUrl = "asset:///im1/" + i + ".jpg";
            p.name = i + "";
            p.imgHeight = (i % 2)*100 + 400; //偶数和奇数的图片设置不同的高度，以到达错开的目的
            list.add(p);
        }

        return list;
    }

}
